<template>
  <section>
    <el-form label-width="80px">
      <el-form-item label="标题">
        <el-input size="mini" v-model="adPosition.description" style="width: 50%;"></el-input>
      </el-form-item>
      <el-form-item label="类型">
        <el-select size="mini" v-model="adPosition.adTypeId">
          <el-option v-for="type in adTypeList" :key="type.id" :value="type.id" :label="type.name"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="客户端ID">
        <el-select size="mini" v-model="adPosition.cId">
          <el-option v-for="client in clientList" :key="client.id" :value="client.id" :label="client.clientName"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="显示数量">
        <el-input style="width:50%" size="mini" v-model="adPosition.data.max" placeholder="请输入该位置最大展示量"></el-input>
      </el-form-item>
    </el-form>
    <get-position v-if="adPosition.cId" :client="adPosition.cId" :adPosition="adPosition.position" v-on:selPosition="selPositionEvent"></get-position>
    <div style="margin-left: 80px">
      <el-button size="mini" :type="adPosition.id?'success':'primary'" @click="confirmBtn">{{adPosition.id?'保存':'新建'}}</el-button>
    </div>
  </section>
</template>

<script>
  import getPosition from './getPosition'//
  import selComDep from '@/components/coupon/selComDep'
  import {mapGetters, mapActions, mapMutations} from 'vuex'
  import Vue from 'vue'//后续添加属性，需要vue联动
  import errHandler from '@/assets/errHandler'
  export default {
    name: "editPosition",
    props:['adPosition'],
    components:{selComDep,getPosition},
    data(){
      return {
        storeAd:false,
        clientList:null,
        adTypeList:null,
        positions:[
          {name:'页眉',code:'banner'},
          {name:'上方',code:'top'},
          {name:'中部',code:'main'},
          {name:'下方',code:'bottom'},
          {name:'页脚',code:'footer'},
        ],
        positionList:[
          {name:'首页页眉',code:'index_banner'},
          {name:'首页上方',code:'index_top'},
          {name:'首页中部',code:'index_main'},
          {name:'首页下方',code:'index_bottom'},
          {name:'首页页脚',code:'index_footer'},
        ]
      }
    },
    watch:{
      storeAd(nv,ov){
      }
    },
    created(){
      console.log(this.adPosition)
      this.getClientList()
      this.getAdTypeList()
    },
    methods: {
      ...mapActions({
        fetch: 'fetch'
      }),
      getDepartmentId(e){
        this.adPosition.departmentId=e.id
      },
      getClientList(){
        this.fetch({name:"getClientList"})
          .then(res=>{
            console.log(res)
            this.clientList=res
          })
          .catch(err=>{
            console.log(err)
            errHandler.handle(this,err)
          })
      },
      getAdTypeList(){
        this.fetch({name:"getAdTypeList"})
          .then(res=>{
            console.log(res)
            this.adTypeList=res
          })
          .catch(err=>{
            console.log(err)
            errHandler.handle(this,err)
          })
      },
      confirmBtn(){
        console.log(this.adPosition)
        this.$emit('save',this.adPosition)
      },
      selPositionEvent(e){
        console.log('控件传来组装好的字符串--------',e)
        this.adPosition.position=e
      }
    }
  }
</script>

<style scoped>

</style>
